package dtt;

import java.util.ArrayList;

public class BusinessRulesBO {

	public BusinessRulesBO() {

	}

	/**
	 * This method returns valid state transition based on the current defect
	 * state and user role
	 * 
	 * @param currentState
	 *            Current defect state
	 * @param userRole
	 *            Role of the user
	 * @return Arraylist of possible defect states.
	 */
	@SuppressWarnings("unchecked")
	public ArrayList getValidStateTransitions(String currentstate,
			String userrole) {
		ArrayList states = new ArrayList();

		// case1: currentstate=submitted, valid future states=Reject,
		// Postponed,Assessed for Roles=
		// ProjectManager
		if (currentstate.equals(Constants.STATE_SUBMITTED)) {
			if (userrole.equals(Constants.ROLE_PROJECT_MANAGER)) {
				states.add(Constants.STATE_ASSESSED);
				states.add(Constants.STATE_POSTPONED);
				states.add(Constants.STATE_REJECTED);
			}//end if project manager
		}//end if submitted

		else if (currentstate.equals(Constants.STATE_ASSESSED)) {
			if (userrole.equals(Constants.ROLE_DEVELOPMENT_LEAD)) {
				states.add(Constants.STATE_ASSIGNED);
				states.add(Constants.STATE_POSTPONED);
				states.add(Constants.STATE_REJECTED);
				states.add(Constants.STATE_SUBMITTED);
			}//end if development lead
		}//end if assessed
		else if (currentstate.equals(Constants.STATE_ASSIGNED)) {
			if (userrole.equals(Constants.ROLE_DEVELOPMENT_STAFF)) {
				states.add(Constants.STATE_RESOLVED);
				states.add(Constants.STATE_REJECTED);
				states.add(Constants.STATE_ASSESSED);
			}//end if development staff
		}//end if assigned
		
		else if (currentstate.equals(Constants.STATE_RESOLVED)) {
			if (userrole.equals(Constants.ROLE_DEVELOPMENT_STAFF)) {
				states.add(Constants.STATE_TESTED);
			}// end development staff
			else if(userrole.equals(Constants.ROLE_TEST_RESOURCE)){
				states.add(Constants.STATE_ASSESSED);
			}//end test resource
		}//end if resolved
		
		else if (currentstate.equals(Constants.STATE_TESTED)) {
			if (userrole.equals(Constants.ROLE_TEST_RESOURCE)) {
				states.add(Constants.STATE_CLOSED);
				}//end if test resource
		}//end if tested
 
		else if (currentstate.equals(Constants.STATE_REJECTED)) {
				states.add(Constants.STATE_CLOSED);
			}//end if rejected
		
		else if (currentstate.equals(Constants.STATE_POSTPONED)) {
			if (userrole.equals(Constants.ROLE_PROJECT_MANAGER)) {
				states.add(Constants.STATE_SUBMITTED);
				}//end if project managaer
		}//end if postponed
		
		
			
		
		
		
		return states;

	}

}
